import sys

print("查看langchain_core.messages模块中的所有类和内容...")

# 尝试导入langchain_core.messages
try:
    import langchain_core.messages as messages
    print("✅ 成功导入langchain_core.messages")
    print(f"模块路径: {messages.__file__}")
    
    # 打印模块中的所有属性
    print("\n模块中的所有属性:")
    for attr_name in dir(messages):
        if not attr_name.startswith('__'):
            attr = getattr(messages, attr_name)
            print(f"- {attr_name}: {type(attr).__name__}")
    
    # 专门查找消息相关的类
    print("\n消息相关的类:")
    for attr_name in dir(messages):
        if not attr_name.startswith('__'):
            attr = getattr(messages, attr_name)
            if isinstance(attr, type):
                print(f"- {attr_name}")
    
    # 检查是否有AnyMessage类
    if hasattr(messages, 'AnyMessage'):
        print("\n✅ 找到AnyMessage类")
        print(f"AnyMessage: {messages.AnyMessage}")
        # 尝试获取AnyMessage的文档字符串
        if messages.AnyMessage.__doc__:
            print(f"文档字符串: {messages.AnyMessage.__doc__[:200]}...")
    else:
        print("\n❌ 未找到AnyMessage类")
        
        # 查找可能的替代类
        print("\n查找可能的消息基类或替代类:")
        for attr_name in dir(messages):
            if not attr_name.startswith('__'):
                attr = getattr(messages, attr_name)
                if isinstance(attr, type) and ('message' in attr_name.lower() or 'any' in attr_name.lower()):
                    print(f"- {attr_name}")
    
    # 查看BaseMessage类，它可能是所有消息的基类
    if hasattr(messages, 'BaseMessage'):
        print("\nBaseMessage类信息:")
        print(f"BaseMessage: {messages.BaseMessage}")
        # 打印BaseMessage的子类
        print("BaseMessage的子类:")
        for subclass in messages.BaseMessage.__subclasses__():
            print(f"  - {subclass.__name__}")
    
    # 查看annotated_types，可能包含AnyMessage的定义
    if hasattr(messages, 'annotated_types'):
        print("\nannotated_types模块:")
        print(f"annotated_types: {messages.annotated_types}")
        
        # 查看annotated_types中的内容
        for attr_name in dir(messages.annotated_types):
            if not attr_name.startswith('__'):
                print(f"  - {attr_name}")
    
    # 查找Union类型，可能AnyMessage是一个Union类型
    print("\n查找Union类型定义:")
    for attr_name in dir(messages):
        if not attr_name.startswith('__'):
            attr = getattr(messages, attr_name)
            # 检查是否是类型联合
            if hasattr(attr, '__origin__') and str(attr.__origin__).find('Union') != -1:
                print(f"- {attr_name}: {attr}")
                
except ImportError as e:
    print(f"❌ 导入失败: {e}")

print("\n查看Director.py文件需要的修复:")
print("1. 修复拼写错误: 'form' -> 'from'")
print("2. 修复导入路径: 'langchain.core.messages' -> 'langchain_core.messages'")
print("3. 根据实际情况调整导入的类")